#分页爬取58租房信息
import requests
import re,time

for i in range(1,30):
	url = 'https://bj.58.com/dashanzi/chuzu/pn%d/'% i

	data = {
		'PGTID':'0d3090a7-01d7-f980-9c15-4f1344d17ba2',
		'ClickID':'1',
	}

	res = requests.get(url,params=data)
	html = res.content.decode('utf-8')
	#print(html)

	pat = 'lazy_src="(.*?)".*?<h2>.*?<a href=.*?>(.*?)</a>.*?<p class="room strongbox">(.*?)&nbsp;&nbsp;&nbsp;&nbsp;(.*?)</p>.*?<b class="strongbox">(.*?)</b>(.*?)</div>'

	dlist = re.findall(pat,html,re.S)

	print("第%d页内容:"%i)
	for i in dlist:
		print('标题: '+re.sub(r'\s+','',i[1])+' '+'户型: '+re.sub(r'\s+','',i[2])+i[3]+' '+'价格:'+i[4]+re.sub(r'\s+','',i[5])+' '+'图片:'+i[0])

	time.sleep(3)


    
